export default {
  data() {
    return {
      pageLoading: false,
      type: '',
      addList: [],
      listIndex: 1,
      status: '',
      roleId: 0,
      title: '暂无地址,请联系管理员添加 '
    }
  },
  onLoad(option) {
    if(option.type){
      this.type = option.type
    }
  },
  onShow() {
    this.roleId = this.$store.state.user.userInfo.role
    this.listIndex = 1
    this.addList = []
    this.getList()
  },
  created() {
    if(this.$store.state.user.userInfo.role!==0){
      this.title = '暂无地址'
    }
  },
  onReachBottom() {
    this.getList()
  },
  methods: {
    more() {
      this.getList()
    },
    // 加载前、中、后
    moreStatus(status) {
      this.status = status
    },
    async getList() {
      this.status = 'loading'
      try {
        let data = {
          PageIndex: this.listIndex,
          PageSize: 10,
          app_type: 0,
        }
        const res = await this.$api.common.addressList(data)
        this.addList = [...this.addList, ...res.data.list]
        this.$nextTick(() => {
          this.pageLoading = true
        })
        if (res.data.total <= 10) {
          this.status = 'nomore'
        } else {
          this.moreStatus(res.data.list.length !== 0 ? 'loadmore' : 'nomore')
        }
        if (res.data.list.length === 0) return false
        this.listIndex += 1 // 当前页加1
        // console.log(res.data.list)
      } catch (e) {
        console.log(e)
      }
    },

    clickOther(item) {
      if (this.type === '110') {
        uni.$emit('Newinquiry', {
          mcdistrict: item.mcdistrict, //区
          mccity: item.mccity,
          mcprovince: item.mcprovince, //省
          address: item.address,
          name: item.name,
          mobile: item.mobile,
          id: item.id,
        })
        uni.navigateBack({
          delta: 1,
        })
      }
    },
    //跳转详情
    goEdit(id) {
      let list = JSON.stringify(id)
      console.log(id, '值')
      uni.navigateTo({
        url: '/pages_common/editAddress/editAddress?addressid=' + list,
      })
    },
    //添加新地址跳转链接
    addnewaddress() {
      uni.navigateTo({
        url: '/pages_common/newAddress/newAddress?length='+this.addList.length,
      })
    },
  },
}
